package com.legendshop.openportal.sdk.utils.signer.validator;

import com.legendshop.openportal.sdk.model.message.SignContent;
import com.legendshop.openportal.sdk.utils.signer.Hmac256ContentSigner;


/**
 * Hmac256 消息验证器
 * @author chan
 */
public class Hmac256ContentValidator implements ContentValidator {

    private String secret;

    public Hmac256ContentValidator(String secret) {
        this.secret = secret;
    }

    @Override
    public boolean isValid(SignContent signContent) {
        if (signContent.expired()) {
            return false;
        }
        String sign = new Hmac256ContentSigner().buildSign(signContent, secret);
        if (!sign.equals(signContent.getSignStr())) {
            return false;
        }
        return true;
    }

}
